package com.quantum.util
{

	public class MathUtils
	{
		/**
		 * Utility method to round up a given number based on
		 * the specified precision.
		 *
		 * For e.g.
		 * If the number is 1.17185 and precision is 1, then
		 * it returns 1.2
		 * If the number is 1.17185 and precision is 2, then
		 * it returns 1.18
		 * If the number is 1.17185 and precision is 3, then
		 * it returns 1.172
		 */
		public static function roundUp(value:Number, precision:int=0):Number
		{
			var n:Number=Math.pow(10, precision);
			return Math.ceil(value * n) / n;
		}

		/**
		 * Utility method to round in the standard arithmetic fashion
		 * (to the nearest integer; round up if value is equidistant
		 * from two nearest integers) based on the specified precision.
		 *
		 * For e.g.
		 * If the number is 1.17185 and precision is 1, then
		 * it returns 1.2
		 * If the number is 1.17185 and precision is 2, then
		 * it returns 1.18
		 * If the number is 1.17185 and precision is 3, then
		 * it returns 1.172
		 * If the number is 1.17185 and precision is 4, then
		 * it returns 1.1719
		 */
		public static function round(value:Number, precision:int=0):Number
		{
			var n:Number=Math.pow(10, precision);
			return Math.round(value * n) / n;
		}
	}
}